<template>
  <div class="app-container">
    <div class="app-top">
      <div class="input-line">
        <span class="input-label">关键词：</span>
        <el-input v-model="tableParam.params" placeholder="请输入" style="width: 210px" clearable />
      </div>
      <div class="input-line">
        <span class="input-label">账号：</span>
        <el-input v-model="tableParam.loginName" placeholder="请输入" style="width: 210px" clearable />
      </div>

      <div>
        <el-button type="primary" icon="el-icon-search" @click="; (tableParam.page = 1), fetchData()">
          搜索
        </el-button>
      </div>
    </div>

    <div class="function" />
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      :header-cell-style="{ background: '#f3f6f9' }"
      :cell-style="{ borderRight: 'none' }"
      tooltip-effect="dark"
    >
      <el-table-column align="center" label="ID" prop="id" width="80" />
      <el-table-column align="center" label="账号" prop="loginName" width="140" />
      <el-table-column align="center" label="ip" prop="ip" width="130" />
      <el-table-column align="center" label="url" prop="url" width="180" />
      <el-table-column align="center" label="参数" prop="params" />
      <el-table-column align="center" label="响应时间" prop="ms" width="80" />

      <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
    </el-table>
    <div class="app-pagination">
      <el-pagination
        :current-page.sync="tableParam.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="tableParam.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="sizeData"
        @current-change="fetchData()"
      />
      <el-button type="primary" size="mini" icon="el-icon-refresh" @click="fetchData()">
        刷新
      </el-button>
    </div>
  </div>
</template>

<script>
import { queryAll } from '@/api/logger'
export default {
  data() {
    return {
      list: [],
      listLoading: true,
      tableParam: {
        page: 1,
        pageSize: 10,
        loginName: '',
        params: ''
      },
      total: null
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    sizeData(e) {
      this.tableParam.page = 1
      this.tableParam.pageSize = e
      this.fetchData()
    },
    fetchData() {
      const _this = this
      _this.listLoading = true
      queryAll(this.tableParam).then((res) => {
        _this.list = res.data.data
        _this.total = res.data.total
        _this.listLoading = false
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.tooltip-content {
  max-width: 460px;
  line-height: 20px;
}
</style>
